package com.hcj.controller;
import com.hcj.util.VerifyCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.IOException;

@RestController
@RequestMapping("/verify")
public class VerifyCodeController {
    @Autowired
    private VerifyCode verifyCode;
    //返回验证码
    @RequestMapping("/getCode")
    public String getCode(HttpServletResponse httpServletResponse) throws IOException {

        BufferedImage image = verifyCode.createImage();
        String text = verifyCode.getText();
        System.out.println("text = " + text);
        //讲验证码设置成图片
        httpServletResponse.setContentType("image/jpeg");
        ImageIO.write(image,"jpg",httpServletResponse.getOutputStream());
        return text;
    }


}